package com.example.web_task.service.impl;

import com.example.web_task.entity.College;
import com.example.web_task.entity.Teacher;
import com.example.web_task.mapper.CollegeMapper;
import com.example.web_task.mapper.TeacherMapper;
import com.example.web_task.service.ICollegeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.web_task.service.ITeacherService;
import com.example.web_task.vo.CollegeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 学院 服务实现类
 * </p>
 *
 * @author suheng
 * @since 2024-02-23
 */
@Service
public class CollegeServiceImpl extends ServiceImpl<CollegeMapper, College> implements ICollegeService {

    @Autowired
    private ITeacherService iTeacherService;
    /*
    根据id查询学院信息
     */
    @Override
    public CollegeVo getMessageById(Long id) {
        College college = this.getById(id);
        if(college==null){
            return null;
        }
        List<Teacher> teacherList=iTeacherService.getByCollegeId(id);
        CollegeVo collegeVo=new CollegeVo();
        BeanUtils.copyProperties(college,collegeVo);
        collegeVo.setTeacherList(teacherList);
        return collegeVo;
    }
}
